﻿using System;
using System.Collections.Generic;
using Demo.DALFactory;
using Demo.IDAL;
using Demo.Model;

namespace Demo.BLL
{
    /// <summary>
    /// BLL层新闻管理类
    /// </summary>
    public class NewsManager
    {

        #region 使用新闻工厂来创建全局对象

        /// <summary>
        /// 新闻对象实例
        /// </summary>
        INewsService iNewsService = NewsFactory.CreateNewsService();

        #endregion

        #region CRUD方法

        /// <summary>
        /// 根据ID，获得指定的新闻数据
        /// </summary>
        /// <param name="ID">新闻ID</param>
        /// <returns>NewsModel</returns>
        public NewsModel GetNewsByID(Int32 ID)
        {
            return iNewsService.GetNewsByID(ID);
        }

        /// <summary>
        /// 获得所有新闻内容
        /// </summary>
        /// <returns> 新闻对象泛型列表 </returns>
        public List<NewsModel> GetAllNews()
        {
            return iNewsService != null ? iNewsService.GetAllNews() : null;
        }

        /// <summary>
        /// 添加一条新闻
        /// </summary>
        /// <param name="news">待添加的新闻对象</param>
        /// <returns>添加成功，返回ture；否则返回false</returns>
        public bool AddNews(NewsModel news)
        {
            return iNewsService.AddNews(news);
        }

        /// <summary>
        /// 修改指定新闻数据
        /// </summary>
        /// <param name="news">待更新的新闻对象(包括该条新闻的ID)</param>
        /// <returns>更新成功，返回ture；否则返回false</returns>
        public bool ModityNewsByID(NewsModel news)
        {
            return iNewsService.ModityNewsByID(news);
        }

        /// <summary>
        ///  删除某条指定的新闻
        /// </summary>
        /// <param name="ID">待删除新闻的ID</param>
        /// <returns>删除成功，返回ture；否则返回false</returns>
        public bool RemoveNewsByID(Int32 ID)
        {
            return iNewsService.RemoveNewsByID(ID);
        }

        #endregion

    }
}
